package cn.itlaobing.web.filter;

import javax.servlet.*;
import javax.servlet.annotation.WebFilter;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * Created by Administrator on 2017/11/20 0020.
 */
@WebFilter("/*")
public class AuthFilter implements Filter{


    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req=(HttpServletRequest)request;
       // HttpServletResponse res=(HttpServletResponse)response;
        req.setCharacterEncoding("UTF-8");
       Integer userId= (Integer)req.getSession().getAttribute("user");
       if(userId==null){
            req.getSession().setAttribute("user",100);
       }
        chain.doFilter(req,response);
    }

    @Override
    public void destroy() {

    }
}
